<?php

/**
 * This is the model class for table "purchase".
 *
 * The followings are the available columns in table 'purchase':
 * @property integer $purchase_id
 * @property integer $purchase_buyer
 * @property integer $purchase_item
 * @property string $purchase_time
 * @property integer $purchase_status
 * @property integer $purchase_rating
 * @property double $purchase_price
 *
 * The followings are the available model relations:
 * @property User $purchaseBuyer0
 * @property Item $purchaseItem0
 */
class Purchase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Purchase the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'purchase';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('purchase_price', 'required'),
			array('purchase_status, purchase_rating', 'numerical', 'integerOnly'=>true),
			array('purchase_price', 'numerical'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('purchase_id, purchase_buyer, purchase_item, purchase_time, purchase_status, purchase_rating, purchase_price', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'purchaseBuyer0' => array(self::BELONGS_TO, 'User', 'purchase_buyer'),
			'purchaseItem0' => array(self::BELONGS_TO, 'Item', 'purchase_item'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'purchase_id' => 'Purchase',
			'purchase_buyer' => 'Purchase Buyer',
			'purchase_item' => 'Purchase Item',
			'purchase_time' => 'Purchase Time',
			'purchase_status' => 'Purchase Status',
			'purchase_rating' => 'Purchase Rating',
			'purchase_price' => 'Purchase Price',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('purchase_id',$this->purchase_id);
		$criteria->compare('purchase_buyer',$this->purchase_buyer);
		$criteria->compare('purchase_item',$this->purchase_item);
		$criteria->compare('purchase_time',$this->purchase_time,true);
		$criteria->compare('purchase_status',$this->purchase_status);
		$criteria->compare('purchase_rating',$this->purchase_rating);
		$criteria->compare('purchase_price',$this->purchase_price);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}